package com.fans.springaop.configure;

import java.lang.reflect.Method;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogServiceAspect {
	 protected static Logger logger = LoggerFactory.getLogger(LogServiceAspect.class);

	    @Pointcut("execution(* com.fans.springaop.service..*.*(..))")
	    public void serviceLog() {
	    }

	    @Around("serviceLog()")
	    public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable {
	    	Long start=System.currentTimeMillis();
	    	Object proceed = joinPoint.proceed();
	    	Long end =System.currentTimeMillis();
	    	MethodSignature signature = (MethodSignature) joinPoint.getSignature();
	        Method method = signature.getMethod();
	    	logger.info(method.getName()+"方法用时"+(end-start)+"毫秒");
	    	return proceed;
	    }

}
